var path = require('path');
var webpack = require('webpack');
 
//指向打包后文件的输出目录
var BUILD_DIR = path.resolve(__dirname, 'client/dist');
//React项目的代码所在目录
var APP_DIR = path.resolve(__dirname, 'client');

module.exports = {
  devtool: 'cheap-module-eval-source-map',
  entry: [
    APP_DIR + '/app.js'
  ],
  output: {
    path: BUILD_DIR,
    filename: 'bundle.js'
  },
  module: {
 
    loaders: [
      {
        test: /\.json$/,
        loader: "json-loader"
      },
      {
        test: /\.js$/,
        exclude: /node_modules/,
        loader: 'babel-loader',
        query: {
          presets: [ 'es2015', 'react' ],
          //antd按需求加载样式
          "plugins":[
            ["import",{"libraryName":"antd","style":true}]
          ]
        }
      },
      {
        test: /\.css$/,
        // loader: "style-loader!css-loader"
        loader:'style-loader!css-loader?modules&importLoaders=1&localIdentName=[name]__[local]__[hash:base64:5]'
      },
      {
        test: /\.less$/,
        // loader: "style-loader!css-loader!less-loader"
        loader:'style-loader!css-loader!less-loader?modules&importLoaders=1&localIdentName=[name]__[local]__[hash:base64:5]'
      },
      {
        test: /\.jsx$/,
        use: [
          'babel-loader',
        ],
        include: [
          // path.resolve(__dirname, "app")
          APP_DIR
        ]
      }
    ]
  } ,
 
  plugins: [
    
          new webpack.HotModuleReplacementPlugin(),
          new webpack.NoEmitOnErrorsPlugin(),
          new webpack.optimize.UglifyJsPlugin({
                  compress: {
                    warnings: false
                }
            }),
            new webpack.DefinePlugin({
                'process.env': {
                    'DEBUG': true,
                    'NODE_ENV': JSON.stringify('production')
                }
            })
        ]
  };